package com.jxb;

import java.util.Date;

import io.jsonwebtoken.JwtBuilder;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import io.jsonwebtoken.impl.Base64Codec;

/**
 * 类注释
 *
 * @author jiaobo
 * @date Created in 2024/10/27 16:06
 **/
public class GenerTest {

    public static void main(String[] args) {
        //创建一个JWTBuilder对象
        JwtBuilder builder = Jwts.builder()
                //声明的标识{"jti":"666"}
                .setId("666")
                //主体，用户{"sub":"Fox"}
                .setSubject("Fox")
                //创建日期{"ita":"xxxx"}
                .setIssuedAt(new Date())
                //增加过期时间
                .setExpiration(new Date(System.currentTimeMillis()+60*1000))
                //签名手段，参数1：算法，参数2：盐
                .signWith(SignatureAlgorithm.HS512,"123123");
        //获取token
        String token = builder.compact();
        System.out.println(token);

        //三部分base64解密
        System.out.println("=================");
        String[] split = token.split("\\.");
        System.out.println(Base64Codec.BASE64.decodeToString(split[0]));
        System.out.println(Base64Codec.BASE64.decodeToString(split[1]));
        //无法解密
        System.out.println(Base64Codec.BASE64.decodeToString(split[2]));
    }

}
